package com.magnificent.atlantis.client.ui.planner.panels.task;

import com.magnificent.atlantis.client.data.task.planner.AbstractPlannerTask;
import com.magnificent.atlantis.client.ui.planner.panels.task.attribute.AbstractTaskAttributePanel;

import javax.swing.*;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;

/**
 * User: Babanin
 * Date: 05.05.2009
 * Time: 18:35:55
 */
public class PlannerTasksPanelContainer extends JPanel {
    private static Map<Class, AbstractTaskAttributePanel> attributePanelMap =
            new HashMap<Class, AbstractTaskAttributePanel>();

    private AbstractTaskAttributePanel currentContentPanel;

    public PlannerTasksPanelContainer() {
        super(new BorderLayout());
        setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    }

    public void taskSelected(AbstractPlannerTask plannerTask) {
        if (currentContentPanel != null) {
            remove(currentContentPanel);
        }

        if (plannerTask != null) {
            currentContentPanel = attributePanelMap.get(plannerTask.getClass());
            currentContentPanel.taskSelected();
            add(currentContentPanel, BorderLayout.CENTER);
        }

        repaint();
        revalidate();
    }

    public AbstractTaskAttributePanel getCurrentContentPanel() {
        return currentContentPanel;
    }

    public static void register(Class taskClass, AbstractTaskAttributePanel panel) {
        attributePanelMap.put(taskClass, panel);
    }
}
